home *** CD-ROM | disk | FTP | other *** search
/ World of Video / World of Video.iso / gfxprograms / 3dprograms / rayshade-4.0 / etc / rsconvert / lex.l next >
Text File  |  1995-02-13  |  4KB  |  168 lines

  1. /* lex.l                                   */
  2. /* Copyright (C) 1989, 1991, Craig E. Kolb                   */
  3. /* All rights reserved.                               */
  4. /*                                       */
  5. /* This software may be freely copied, modified, and redistributed,       */
  6. /* provided that this copyright notice is preserved on all copies.       */
  7. /*                                       */
  8. /* You may not distribute this software, in whole or in part, as part of   */
  9. /* any commercial product without the express consent of the authors.       */
  10. /*                                        */
  11. /* There is no warranty or other guarantee of fitness of this software       */
  12. /* for any purpose.  It is provided solely "as is".               */
  13. /* lex.l,v 4.1 1994/08/09 07:53:29 explorer Exp */
  14. %{
  15. #include "config.h"
  16. #include <stdio.h>
  17. #ifdef I_STRING
  18. #include <string.h>
  19. #else
  20. #include <strings.h>
  21. #endif
  22. #include "libcommon/common.h"
  23. #include "y.tab.h"
  24. %}
  25. alpha    [a-zA-Z]
  26. special    [\.\_-]
  27. digit    [0-9]
  28. exp    [Ee][-+]?{digit}+
  29. string    ({alpha}|"/")({alpha}|{digit}|{special}|"/")*
  30. %p 3000
  31. %%
  32. [\t]            {WriteVerbatim(yytext);};
  33. "\n"                    {};
  34. " "            {};
  35. ^#            {return handlehash();}
  36. "/*"            {skipcomments();}
  37. adaptive        {return(tADAPTIVE);}
  38. aperture        {return(tAPERTURE);}
  39. background        {return(tBACKGROUND);}
  40. blotch            {return(tBLOTCH);}
  41. box            {return(tBOX);}
  42. bump            {return(tBUMP);}
  43. checker            {return(tCHECKER);}
  44. cone            {return(tCONE);}
  45. contrast        {return(tCONTRAST);}
  46. cutoff            {return(tCUTOFF);}
  47. cylinder        {return(tCYL);}
  48. defend            {return(tENDDEF);}
  49. define            {return(tSTARTDEF);}
  50. directional        {return(tDIRECTIONAL);}
  51. endfile            {return(tENDFILE);}
  52. extended        {return(tEXTENDED);}
  53. eyep            {return(tEYEP);}
  54. fbm            {return(tFBM);}
  55. fbmbump            {return(tFBMBUMP);}
  56. focaldist        {return(tFOCALDIST);}
  57. fog            {return(tFOG);}
  58. fov            {return(tFOV);}
  59. gloss            {return(tGLOSS);}
  60. grid            {return(tGRID);}
  61. heightfield        {return(tHEIGHTFIELD);}
  62. jittered        {return(tJITTERED);}
  63. light            {return(tLIGHT);}
  64. list            {return(tLIST);}
  65. lookp            {return(tLOOKP);}
  66. marble            {return(tMARBLE);}
  67. maxdepth        {return(tMAXDEPTH);}
  68. mist            {return(tMIST);}
  69. object            {return(tOBJECT);}
  70. outfile            {return(tOUTFILE);}
  71. plane            {return(tPLANE);}
  72. point            {return(tPOINT);}
  73. poly            {return(tPOLY);}
  74. resolution        {return(tRESOLUTION);}
  75. rotate            {return(tROTATE);}
  76. samples            {return(tSAMPLES);}
  77. scale            {return(tSCALE);}
  78. screen            {return(tSCREEN);}
  79. sphere            {return(tSPHERE);}
  80. superq            {return(tSUPERQ);}
  81. surface            {return(tSURFACE);}
  82. texture            {return(tTEXTURE);}
  83. transform        {return(tTRANSFORM);}
  84. translate        {return(tTRANSLATE);}
  85. triangle        {return(tTRIANGLE);}
  86. up            {return(tUP);}
  87. wood            {return(tWOOD);}
  88. {string}        {yylval.c = strsave(yytext);
  89.                 return(tSTRING);}
  90. [+-]?{digit}+        {yylval.i = atoi(yytext);
  91.                 return(tINT);}
  92.  
  93. [+-]?{digit}+"."{digit}*({exp})? |
  94. [+-]?{digit}*"."{digit}+({exp})? |
  95. [+-]?{digit}+{exp}        {yylval.d = atof(yytext); return(tFLOAT);}
  96.  
  97. .            {return yytext[0];}
  98.  
  99. %%
  100. #ifdef yywrap
  101. #undef yywrap
  102. #endif
  103. yywrap() {return(1);}
  104. /*
  105.  * Skip over comments.
  106.  */
  107. skipcomments()
  108. {
  109.     char c;
  110.  
  111.     WriteVerbatim("/*");
  112.     while (1) {
  113.         while ((c = input()) != '*')
  114.             WriteChar(c);
  115.         WriteChar(c);
  116.         if ((c = input()) == '/') {
  117.             WriteChar(c);
  118.             WriteNewline();
  119.             return;
  120.         }
  121.         unput(c);
  122.     }
  123. }
  124. /*
  125.  * Deal with ccp-produced lines of the form:
  126.  * # n "filename"
  127.  * and
  128.  * # n
  129.  * Where filename is the name of the file being processed, and n is
  130.  * the current line number in that file.
  131.  */
  132. handlehash()
  133. {
  134.     char buf[BUFSIZ];
  135.     int i, linenumber;
  136.     extern int yylineno;
  137.     extern char yyfilename[];
  138.  
  139.     /*
  140.      * Read the entire line into buf.
  141.      */
  142.     for (i = 0; (buf[i] = input()) != '\n'; i++)
  143.             ;
  144.     unput(buf[i]);        /* To make sure consecutive # lines work. */
  145.     buf[i] = (char)NULL;    /* Replace newline with NULL. */
  146.  
  147.     yylval.c = strsave(buf);
  148.  
  149.     /*
  150.      * Set file/line if the line was of the form #n "filename"
  151.      */
  152.     if ((i = sscanf(buf, "%d \"%[^\"]s\"", &linenumber, buf)) != 0) {
  153.         yylineno = linenumber;
  154. #ifdef SYSV
  155.         if (strchr(buf, '"') != (char *)0) {
  156. #else
  157.         if (index(buf, '"') != (char *)0) {
  158. #endif
  159.             /*
  160.              * Filename was "", which means stdin.
  161.              */
  162.             strcpy(yyfilename, "stdin");
  163.         } else
  164.             strcpy(yyfilename, buf);
  165.     }
  166.     return tHASHTHING;
  167. }
  168.